package com.clock.controller.stage;


import com.clock.common.constant.HttpStatus;
import com.clock.common.domain.R;
import com.clock.domain.entity.ChickenSoup;
import com.clock.service.ChickenSoupService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Api(tags = {"鸡汤接口"})
@RestController
@RequestMapping("/chicken")
public class ChickenSoupController {

    @Resource
    ChickenSoupService chickenSoupService;

    @ApiOperation(value = "获取鸡汤接口", notes = "不用参数")
    @GetMapping("/getChicken")
    public R getChickenSoup() {
        String chickenSoup = chickenSoupService.getChickenSoup();
        if (chickenSoup == null) {
            chickenSoup = "今天的鸡汤失踪了,但不可抵挡的是你努力学习的决心";
        }

        return R.ok(null, chickenSoup, null);
    }

    @ApiOperation(value = "获取鸡汤剩余数量接口", notes = "不用参数")
    @GetMapping("/getChickenCount")
    public R getChickenSoupCount() {
        Long chickenCount = chickenSoupService.getChickenCount();
        if(chickenCount!=null){
            return R.ok(chickenCount);
        }
        return R.fail();
    }

    @ApiOperation(value = "新增鸡汤接口", notes = "只需要鸡汤内容")
    @PostMapping("/addChicken")
    public R addChickenSoup(@RequestBody @Validated ChickenSoup chickenSoup){
        if(chickenSoup.getSoupContent()==null || chickenSoup.getSoupContent()=="" ||chickenSoup.getSoupContent()==" "){
            return R.fail("请正确输入标签");
        };
        Integer integer = chickenSoupService.addChickenSoup(chickenSoup);
        if(integer>=1){
            return R.ok();
        }else{
            return R.fail();
        }
    }

   /* @ApiOperation(value = "批量新增鸡汤接口", notes = "只需要鸡汤内容，每句鸡汤以英文的分号(;)做间隔")
    @PostMapping("/batchAddChicken")
    public R batchAddChickenSoup(@RequestBody @Validated ChickenSoup chickenSoup){
        Integer integer = chickenSoupService.batchAddChickenSoup(chickenSoup);
        if(integer>=1){
            return R.ok();
        }else{
            return R.fail();
        }
    }*/

}
